<?php
session_start();
 try{
		        include_once "src/facebook.php";
		    }
		    catch(Exception $o){
		        error_log($o);
		    }
//require 'functions.php';  // Include functions
 $facebook = new Facebook(array(
		      'appId'  => '700715950012686',
		      'secret' => 'a33a75e4bafc2b72b52e12d49a49a594',
		      'cookie' => true
		    ));
			


$user = $facebook->getUser();


if ($user) {
  try {
    $user_profile = $facebook->api('/me','GET');
  	    $_SESSION['userid'] = $user_profile['id'];                 // To Get Facebook ID
 	    $_SESSION['username'] = $user_profile['name'];  // To Get Facebook Username
 	   // $_SERVER['fullname'] = $user_profile['name']; // To Get Facebook full name
	   // $_SERVER['email'] = $user_profile['email'];    // To Get Facebook email ID
    //       checkuser($fbid,$fbuname,$fbfullname,$femail);    // To update local DB
    header("location:/eclipseproject/index.php");
  } catch (FacebookApiException $e) {
    error_log($e);
   $user = null;
  }
}
if (isset($_SESSION['userid'])) {
 $logoutUrl = $facebook->getLogoutUrl(array(
		 'next' => '/eclipseproject/logout.php',  // Logout URL full path
		));
$_SESSION['logout'] = $logoutUrl;
} else {
 $loginUrl = $facebook->getLoginUrl(array(
		'scope'		=> 'email', // Permissions to request from the user
		));
header("location:".$loginUrl."");
}
?>